
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Mock.toJSONSchema() · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Thanks-&-Contributors.html" />
    
    
    <link rel="prev" href="Mock.valid.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="Getting-Started.html">
            
                <a href="Getting-Started.html">
            
                    
                    开始 & 安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html">
            
                    
                    数据模板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#数据模板定义规范-dtd">
            
                    
                    数据模板定义规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#1-属性值是字符串-string">
            
                    
                    String
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#2-属性值是数字-number">
            
                    
                    Number
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#3-属性值是布尔型-boolean">
            
                    
                    Boolean
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#4-属性值是对象-object">
            
                    
                    Object
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#5-属性值是数组-array">
            
                    
                    Array
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#6-属性值是函数-function">
            
                    
                    Function
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#7-属性值是正则表达式-regexp">
            
                    
                    RegExp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="Syntax-Specification.html">
            
                <a href="Syntax-Specification.html#数据占位符定义规范-dtd">
            
                    
                    数据占位符定义规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="Mock.mock.html">
            
                <a href="Mock.mock.html">
            
                    
                    Mock.mock()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Mock.setup.html">
            
                <a href="Mock.setup.html">
            
                    
                    Mock.setup()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Mock.Random.html">
            
                <a href="Mock.Random.html">
            
                    
                    Mock.Random()
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="Basic.html">
            
                <a href="Basic.html">
            
                    
                    Basic
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1.1" data-path="Basic.html">
            
                <a href="Basic.html#randomboolean-min-max-current-">
            
                    
                    boolean
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.2" data-path="Basic.html">
            
                <a href="Basic.html#randomnatural-min-max-">
            
                    
                    natural
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.3" data-path="Basic.html">
            
                <a href="Basic.html#randominteger-min-max-">
            
                    
                    integer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.4" data-path="Basic.html">
            
                <a href="Basic.html#randomfloat-min-max-dmin-dmax-">
            
                    
                    float
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.5" data-path="Basic.html">
            
                <a href="Basic.html#randomcharacter-pool-">
            
                    
                    character
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.6" data-path="Basic.html">
            
                <a href="Basic.html#randomstring-pool-min-max-">
            
                    
                    string
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.7" data-path="Basic.html">
            
                <a href="Basic.html#randomrange-start-stop-step-">
            
                    
                    range
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="Date.html">
            
                <a href="Date.html">
            
                    
                    Date
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.2.1" data-path="Date.html">
            
                <a href="Date.html#randomdate-format-">
            
                    
                    date
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.2" data-path="Date.html">
            
                <a href="Date.html#randomtime-format-">
            
                    
                    timeDate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.3" data-path="Date.html">
            
                <a href="Date.html#randomdatetime-format-">
            
                    
                    datetime
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.4" data-path="Date.html">
            
                <a href="Date.html#randomnow-unit-format-">
            
                    
                    now
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="Image.html">
            
                <a href="Image.html">
            
                    
                    Image
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.3.1" data-path="Image.html">
            
                <a href="Image.html">
            
                    
                    img
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3.2" data-path="Image.html">
            
                <a href="Image.html">
            
                    
                    dataImage
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="Color.html">
            
                <a href="Color.html">
            
                    
                    Color
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.4.1" data-path="Color.html">
            
                <a href="Color.html#randomcolor">
            
                    
                    color
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4.2" data-path="Color.html">
            
                <a href="Color.html#randomhex">
            
                    
                    hex
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4.3" data-path="Color.html">
            
                <a href="Color.html#randomrgb">
            
                    
                    rgb
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4.4" data-path="Color.html">
            
                <a href="Color.html#randomhsl">
            
                    
                    hsl
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="Text.html">
            
                <a href="Text.html">
            
                    
                    Text
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.5.1" data-path="Text.html">
            
                <a href="Text.html#randomparagraph-min-max-">
            
                    
                    paragraph
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.2" data-path="Text.html">
            
                <a href="Text.html#randomsentence-min-max-">
            
                    
                    sentence
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.3" data-path="Text.html">
            
                <a href="Text.html#randomword-min-max-">
            
                    
                    word
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.4" data-path="Text.html">
            
                <a href="Text.html#randomtitle-min-max-">
            
                    
                    title
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.5" data-path="Text.html">
            
                <a href="Text.html#randomcparagraph-min-max-">
            
                    
                    cparagraph
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.6" data-path="Text.html">
            
                <a href="Text.html#randomcsentence-min-max-">
            
                    
                    csentence
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.7" data-path="Text.html">
            
                <a href="Text.html#randomcword-pool-min-max-">
            
                    
                    cword
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5.8" data-path="Text.html">
            
                <a href="Text.html#randomctitle-min-max-">
            
                    
                    ctitlec
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="Name.html">
            
                <a href="Name.html">
            
                    
                    Name
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="Web.html">
            
                <a href="Web.html">
            
                    
                    Web
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="Address.html">
            
                <a href="Address.html">
            
                    
                    Address
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="Helper.html">
            
                <a href="Helper.html">
            
                    
                    Helper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="Miscellaneous.html">
            
                <a href="Miscellaneous.html">
            
                    
                    Miscellaneous
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Mock.valid.html">
            
                <a href="Mock.valid.html">
            
                    
                    Mock.valid()
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8" data-path="Mock.toJSONSchema.html">
            
                <a href="Mock.toJSONSchema.html">
            
                    
                    Mock.toJSONSchema()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Thanks-&-Contributors.html">
            
                <a href="Thanks-&-Contributors.html">
            
                    
                    感谢 & 贡献者
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Mock.toJSONSchema()</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <!-- API Specification -->
<h2 id="mocktojsonschema-template-">Mock.toJSONSchema( template )</h2>
<ul>
<li>Mock.toJSONSchema( template )</li>
</ul>
<p>&#x628A; Mock.js &#x98CE;&#x683C;&#x7684;&#x6570;&#x636E;&#x6A21;&#x677F; <code>template</code> &#x8F6C;&#x6362;&#x6210; <a href="http://json-schema.org/" target="_blank">JSON Schema</a>&#x3002;</p>
<h3 id="template">template</h3>
<p>&#x5FC5;&#x9009;&#x3002;</p>
<p>&#x8868;&#x793A;&#x6570;&#x636E;&#x6A21;&#x677F;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x5BF9;&#x8C61;&#x6216;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x4F8B;&#x5982; <code>{ &apos;list|1-10&apos;:[{}] }</code>&#x3001;<code>&apos;@EMAIL&apos;</code>&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> template = {
    <span class="hljs-string">&apos;key|1-10&apos;</span>: <span class="hljs-string">&apos;&#x2605;&apos;</span>
}
Mock.toJSONSchema(template)
<span class="hljs-comment">// =&gt;</span>
{
    <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-literal">undefined</span>,
    <span class="hljs-string">&quot;path&quot;</span>: [
        <span class="hljs-string">&quot;ROOT&quot;</span>
    ],
    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;object&quot;</span>,
    <span class="hljs-string">&quot;template&quot;</span>: {
        <span class="hljs-string">&quot;key|1-10&quot;</span>: <span class="hljs-string">&quot;&#x2605;&quot;</span>
    },
    <span class="hljs-string">&quot;rule&quot;</span>: {},
    <span class="hljs-string">&quot;properties&quot;</span>: [{
        <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;key&quot;</span>,
        <span class="hljs-string">&quot;path&quot;</span>: [
            <span class="hljs-string">&quot;ROOT&quot;</span>,
            <span class="hljs-string">&quot;key&quot;</span>
        ],
        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,
        <span class="hljs-string">&quot;template&quot;</span>: <span class="hljs-string">&quot;&#x2605;&quot;</span>,
        <span class="hljs-string">&quot;rule&quot;</span>: {
            <span class="hljs-string">&quot;parameters&quot;</span>: [<span class="hljs-string">&quot;key|1-10&quot;</span>, <span class="hljs-string">&quot;key&quot;</span>, <span class="hljs-literal">null</span>, <span class="hljs-string">&quot;1-10&quot;</span>, <span class="hljs-literal">null</span>],
            <span class="hljs-string">&quot;range&quot;</span>: [<span class="hljs-string">&quot;1-10&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>, <span class="hljs-string">&quot;10&quot;</span>],
            <span class="hljs-string">&quot;min&quot;</span>: <span class="hljs-number">1</span>,
            <span class="hljs-string">&quot;max&quot;</span>: <span class="hljs-number">10</span>,
            <span class="hljs-string">&quot;count&quot;</span>: <span class="hljs-number">3</span>,
            <span class="hljs-string">&quot;decimal&quot;</span>: <span class="hljs-literal">undefined</span>,
            <span class="hljs-string">&quot;dmin&quot;</span>: <span class="hljs-literal">undefined</span>,
            <span class="hljs-string">&quot;dmax&quot;</span>: <span class="hljs-literal">undefined</span>,
            <span class="hljs-string">&quot;dcount&quot;</span>: <span class="hljs-literal">undefined</span>
        }
    }]
}
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> template = {
    <span class="hljs-string">&apos;list|1-10&apos;</span>: [{}]
}
Mock.toJSONSchema(template)
<span class="hljs-comment">// =&gt;</span>
{
    <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-literal">undefined</span>,
    <span class="hljs-string">&quot;path&quot;</span>: [<span class="hljs-string">&quot;ROOT&quot;</span>],
    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;object&quot;</span>,
    <span class="hljs-string">&quot;template&quot;</span>: {
        <span class="hljs-string">&quot;list|1-10&quot;</span>: [{}]
    },
    <span class="hljs-string">&quot;rule&quot;</span>: {},
    <span class="hljs-string">&quot;properties&quot;</span>: [{
        <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;list&quot;</span>,
        <span class="hljs-string">&quot;path&quot;</span>: [<span class="hljs-string">&quot;ROOT&quot;</span>, <span class="hljs-string">&quot;list&quot;</span>],
        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;array&quot;</span>,
        <span class="hljs-string">&quot;template&quot;</span>: [{}],
        <span class="hljs-string">&quot;rule&quot;</span>: {
            <span class="hljs-string">&quot;parameters&quot;</span>: [<span class="hljs-string">&quot;list|1-10&quot;</span>, <span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-literal">null</span>, <span class="hljs-string">&quot;1-10&quot;</span>, <span class="hljs-literal">null</span>],
            <span class="hljs-string">&quot;range&quot;</span>: [<span class="hljs-string">&quot;1-10&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>, <span class="hljs-string">&quot;10&quot;</span>],
            <span class="hljs-string">&quot;min&quot;</span>: <span class="hljs-number">1</span>,
            <span class="hljs-string">&quot;max&quot;</span>: <span class="hljs-number">10</span>,
            <span class="hljs-string">&quot;count&quot;</span>: <span class="hljs-number">6</span>,
            <span class="hljs-string">&quot;decimal&quot;</span>: <span class="hljs-literal">undefined</span>,
            <span class="hljs-string">&quot;dmin&quot;</span>: <span class="hljs-literal">undefined</span>,
            <span class="hljs-string">&quot;dmax&quot;</span>: <span class="hljs-literal">undefined</span>,
            <span class="hljs-string">&quot;dcount&quot;</span>: <span class="hljs-literal">undefined</span>
        },
        <span class="hljs-string">&quot;items&quot;</span>: [{
            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-number">0</span>,
            <span class="hljs-string">&quot;path&quot;</span>: [<span class="hljs-string">&quot;data&quot;</span>, <span class="hljs-string">&quot;list&quot;</span>, <span class="hljs-number">0</span>],
            <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;object&quot;</span>,
            <span class="hljs-string">&quot;template&quot;</span>: {},
            <span class="hljs-string">&quot;rule&quot;</span>: {},
            <span class="hljs-string">&quot;properties&quot;</span>: []
        }]
    }]
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Mock.valid.html" class="navigation navigation-prev " aria-label="Previous page: Mock.valid()">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Thanks-&-Contributors.html" class="navigation navigation-next " aria-label="Next page: 感谢 & 贡献者">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Mock.toJSONSchema()","level":"1.8","depth":1,"next":{"title":"感谢 & 贡献者","level":"1.9","depth":1,"path":"Thanks-&-Contributors.md","ref":"./Thanks-&-Contributors.md","articles":[]},"previous":{"title":"Mock.valid()","level":"1.7","depth":1,"path":"Mock.valid.md","ref":"./Mock.valid.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"Mock.toJSONSchema.md","mtime":"2019-01-02T03:55:46.286Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-01-02T04:01:33.354Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

